home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / cutils.arc / STRING.ASM < prev    next >
Encoding:
Assembly Source File  |  1985-08-30  |  4.0 KB  |  112 lines

  1.                         TITLE   String Commands for Lattice Library
  2.                         NAME    STRING
  3.                         INCLUDE DOS.MAC
  4.  
  5. COMMENT #
  6.                 AUTHOR          Jon Wesener
  7.                 DATE            7 / 8 / 1985
  8.                 PURPOSE           These are support routines for use
  9.                                 with C and Assembler.  They are quick
  10.                                 string functions I need a lot.
  11.         #
  12.  
  13.                 PSEG
  14.                 PUBLIC  STRLEN, STRCPY, STRCAT, STRCMP, STRCOM
  15.  
  16. ; Strlen gives the length of a string minus the terminator, 0.
  17. ;  strlen(string)
  18. ; RETURN: length of string.
  19.  
  20. STRLEN          PROC    NEAR
  21.                 push    bp
  22.                 mov     bp, sp
  23.                 xor     ax, ax          ; search for terminator 0
  24.                 mov     di, [bp+4]      ; get string
  25.                 mov    cx, 0ffffh    ; don't get stopped before we start
  26.                 repne   scasb
  27.                 mov     ax, [bp+4]      ; get start position
  28.                 xchg    ax, di          ; switch them around
  29.                 sub     ax, di
  30.                 dec     ax              ; subtract terminator
  31.                 pop     bp
  32.                 ret
  33. STRLEN          ENDP
  34.  
  35. ; Strcpy copies the second string into the first
  36. ;  strcpy(to,from)
  37. ; RETURN: nothing
  38.  
  39. STRCPY          PROC    NEAR
  40.                 push    bp
  41.                 mov     bp, sp
  42.                 mov     si, [bp+6]      ; get from string
  43.                 mov     di, [bp+4]      ; get to string
  44. scl1:           lodsb                   ; read a byte
  45.                 stosb                   ; copy it
  46.                 and     al, al          ; is it the end ?
  47.                 jnz     scl1            ; nope, continue
  48.                 pop     bp
  49.                 ret
  50. STRCPY          ENDP
  51.  
  52. ; Strcat concatenates a string to the end of another.
  53. ;  strcat(to,from);
  54. ; RETURN: nothing
  55.  
  56. STRCAT          PROC    NEAR
  57.                 push    bp
  58.                 mov     bp, sp
  59.                 push    [bp+4]          ; push the to string
  60.                 call    strlen          ; find its length
  61.                 add     ax, [bp+4]      ; find the end of it
  62.                 push    ax              ; push new to string
  63.                 push    [bp+6]          ; push the from string
  64.                 call    strcpy
  65.                 mov     sp, bp          ; clear the stack
  66.                 pop     bp
  67.                 ret
  68. STRCAT          ENDP
  69.  
  70. ; Strcmp compares two string to see if they are the same.
  71. ;  strcmp(string1, string2)
  72. ; RETURN: 1= equal      0= not equal
  73.  
  74. STRCMP          PROC    NEAR
  75.                 push    bp
  76.                 mov     bp, sp
  77.                 mov     si, [bp+4]
  78.                 mov     di, [bp+6]
  79. stcml1:         cmpsb                   ; compare two bytes
  80.                 jnz     stcmne          ; they aren't equal
  81.                 test    byte ptr [si-1], 0ffh
  82.                 jnz     stcml1          ; not done yet
  83.                 mov     ax, 1           ; signal equal
  84. stcmex:         pop     bp
  85.                 ret
  86. stcmne:         xor     ax, ax          ; signal not equal
  87.                 jmp     stcmex
  88. STRCMP          ENDP
  89.  
  90. ; Strcom will return the 128 byte buffer containing the command line.
  91. ;  strcom(buf);
  92. ; RETURN:       nothing
  93. ; NOTE: THIS WILL ONLY WORK FOR .COM PROGRAMS
  94.  
  95. STRCOM          PROC    NEAR
  96.                 push    bp
  97.                 mov     bp, sp
  98.                 mov     di, [bp+4]      ; pt to buffer
  99.                 mov     si, 80h
  100.                 push    cs
  101.                 pop     ds              ; pt to source
  102.                 mov     cx, 80h         ; get 128 bytes
  103.                 rep     movsb           ; copy it over
  104.                 push    es
  105.                 pop     ds              ; restore data segment
  106.                 pop     bp
  107.                 ret
  108. STRCOM          ENDP
  109.                 ENDPS
  110.                 END
  111.  
  112.